package fem2.material.cohesive_law;

import fem2.Element;
import inf.jlinalg.Array2DMatrix;
import inf.jlinalg.ArrayVector;
import inf.jlinalg.IMatrix;
import inf.jlinalg.IVector;

/**
 * Mode I cohesive law based on Linder-Armero paper: Finite elements with
 * embedded strong discontinuities for the modeling of failure in solids
 * 
 * @author hbui
 * 
 */
public class Mode1LACohesiveLaw extends CohesiveLaw {

	private double km;
	private double da;
	private double d0;
	private double k;

	public Mode1LACohesiveLaw(double Gf, double ft, double km, double da, double d0, double k) {
		super(Gf, ft);
		this.km = km;
		this.da = da;
		this.d0 = d0;
		this.k = k;
	}

	@Override
	public IVector computeJumpTraction(Element e, IVector w) {
		double wn = w.get(0);
		double wm = w.get(1);
		double tn, tm;
		if (wn < da) {
			tn = ft * (1 - Math.pow(da / d0, k) * wn / da);
		} else {
			tn = ft / (1 - Math.pow(da / d0, k)) * Math.pow(1 - Math.pow(wn / d0, k), 2);
		}
		tm = km * wm;
		return new ArrayVector(tn, tm);
	}

	@Override
	public IMatrix computeJumpStiffness(Element e, IVector w) {
		double wn = w.get(0);
		double c00;
		if (wn < da) {
			c00 = -Math.pow(da / d0, k) * ft / da;
		} else {
			c00 = ft / (1 - Math.pow(da / d0, k)) * 2 * (1 - Math.pow(wn / d0, k)) * (-k / d0)
					* Math.pow(wn / d0, k - 1);
		}
		double[][] C = new double[][] { { c00, 0.0 }, { 0.0, km } };
		return new Array2DMatrix(C);
	}
}
